#include "StdAfx.h"
#include "CardImage.h"

using namespace SHGame;
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Drawing;

int CardImage::getSuitNum(Card^ c) {
	switch (c->getSuit()) {
		case Card::Suit::Clubs:
			return 0;
		case Card::Suit::Diamonds:
			return 1;
		case Card::Suit::Hearts:
			return 2;
		case Card::Suit::Spades:
			return 3;
		default:
			return -1;
	}
}

int CardImage::getFaceNum(Card^ c) {
	switch (c->getFace()) {
		case Card::Face::Ace:
			return 0;
		case Card::Face::Seven:
			return 6;
		case Card::Face::Eight:
			return 7;
		case Card::Face::Nine:
			return 8;
		case Card::Face::Ten:
			return 9;
		case Card::Face::Jack:
			return 10;
		case Card::Face::Queen:
			return 11;
		case Card::Face::King:
			return 12;
		default:
			return -1;
	}
}

String^ CardImage::getFileName(Card ^c) {
	String ^ str = "card-";
	str = str + CardImage::getFaceNum(c);
	str = str + "-";
	str = str + CardImage::getSuitNum(c);
	str = str + ".png";
	return str;
}

Image^ CardImage::getImage(Card^ c) {
	return getImage(c, false);
}

Image^ CardImage::getImage(Card^ c, bool selected) {
	String^ str = CardImage::getFileName(c);
	if (selected)
		str = HICOLOR_PATH + str;
	else
		str = LOCOLOR_PATH + str;
	return loadImage(str);
}

Image^ CardImage::loadImage(String^ file) {
	
	if (map->ContainsKey(file)) {
		return map[file];
	} else {
		Image^ img = Image::FromFile(file);
		map->Add(file, img);
		return img;
	}
	return nullptr;
}

Image^ CardImage::getImage() {
	return CardImage::getImage(this->card, this->selected);
}